package com.hm.scala.regular

import scala.util.matching.Regex

object RegularTest {

  def main(args: Array[String]): Unit = {

    //正则表达式查找数据
    val pa: Regex = "[0-9]+".r;
    for (i <- pa.findAllIn("rdctvybuioml23ftgyuhijk")) {
      println(i)
    }

    //数据查找替换
    var pa2 = """\d+""".r replaceAllIn ("你好123,你吃饭了没?123今天我们去打游戏吧", "兽兽")
    println(pa2)

    //正则表达式组数据提取
    var pa3: Regex = "([0-9]+) ([a-z]+)".r;
    var str = "1234 abcd";
    println("---------------")
    for (pa3(k, l) <- pa3.findAllIn(str)) {
      println(k + "-------" + l)
    }

    val pa3(a, b) = str;
    println(a + ";" + b)

    //对要匹配的数据顺序，数据个数有要求
    //    str = "abcd 1232";
    //    val pa3(c, e) = str;
    //    println(c + ";" + e)

    //match，如java switch语句

    var pa4 = "([a-z]+) ([0-9]+)".r;

    "qwqedq 34567890" match {
      case pa4(str, num) => println("找到结果集" + str + "=========>" + num)
      case _             => println("没找到数据")
    }

    println("--------------------")

    "qwqedq 34567890 as1212" match {
      case pa4(str, num) => println("找到结果集" + str + "=========>" + num)
      case _             => println("没找到数据")
    }

  }
}